package com.condominio.servlet.queja;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.condominio.excepcion.DAOExcepcion;
import com.condominio.modelo.Persona;
import com.condominio.negocio.QuejaNegocio;

/**
 * Servlet implementation class ActualizarQuejaServlet
 */
@WebServlet("/ActualizarQuejaServlet")
public class ActualizarQuejaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ActualizarQuejaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		HttpSession session = request.getSession();
		Persona oUsuario = (Persona)session.getAttribute("USUARIO_ACTUAL");	
		if(oUsuario == null){
			request.getRequestDispatcher("error.jsp").forward(request, response);
			return;
		}
		
		System.out.println("Dentro de doPost del servlet ActualizarQuejaServlet");

		String observacion		= request.getParameter("observacion");
		String coEstado		= request.getParameter("cmbEstado");
		int coQueja		= Integer.parseInt(request.getParameter("codigo"));
		
		QuejaNegocio dao = new QuejaNegocio();
		try {
			dao.updateQueja( coQueja, coEstado, observacion);
			response.sendRedirect(request.getContextPath() + "/QuejaListarServlet");
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}

}
